package user

import (
	"github.com/zeromicro/go-zero/core/logx"
	"github.com/zeromicro/go-zero/rest/httpx"
	"navi-mumbai/app/api/business/internal/logic/user"
	"navi-mumbai/app/api/business/internal/svc"
	"navi-mumbai/app/api/business/internal/types"
	"navi-mumbai/common/httpresult"
	"net/http"
)

func UserRegisterHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		logx.WithContext(r.Context()).Debugf("receive msg header %v", w.Header())

		var req types.UserRegisterReq
		if err := httpx.Parse(r, &req); err != nil {
			httpresult.ParamErrorResult(r, w, err)
			return
		}
		logx.WithContext(r.Context()).Debugf("receive msg request %v", req)

		l := user.NewUserRegisterLogic(r.Context(), svcCtx)
		resp, err := l.UserRegister(&req, httpx.GetRemoteAddr(r))
		httpresult.HttpResult(r, w, &req, resp, err)
	}
}
